<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件</title>
    <style>

         .box{
             width: 100px;
             height: 100px;
             background-color: greenyellow;
             text-align: center;
             line-height: 100px;
         }

        .active{
            background-color: red;
        }

    </style>
</head>
<body>
<input type="text" id="msg"/>
<div id="message" class="box"></div>

</body>
<script>

   /*  var message = document.getElementById('message');
     message.onmouseover = function () {
         this.innerText ="我进来了！";
         this.classList.add('active');
     }
     message.onmouseout = function () {
         this.innerText ="我离开了！";
         this.classList.remove('active');
     }*/
var msg=  document.getElementById('msg');
msg.onkeypress = function () {
    var message = document.getElementById('message');
    message.innerText = msg.value;
}

</script>
</html>